# -*- coding: UTF-8 -*-
# # decorator test



def document_it(fn):
    '''装饰器：输入函数，返回函数'''
    def newfn(*args, **kwargs):
        print("运行：", fn.__name__)

        res = fn(*args, **kwargs)

        print("结果：", res)
        return res
    
    return newfn

def square_it(fn):
    '''平方装饰器'''
    def newfn(*args, **kwargs):
        res = fn(*args, **kwargs)
        return res * res
    
    return newfn

# 直接在需要装饰的函数前添加装饰器名字：@decorator_name
@document_it
@square_it # 可添加多个decorator，从上往下执行
def add_int(a, b):
    return a + b


def main():
    print("装饰器")
    add_int(5, 4)

if __name__ == "__main__":
    main()
    